using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;   
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LAFDC.DataAccess;
using LAFDC.Web.UI;
using LAFDC.Logging;

namespace LAFDC.Web.UI {
    public partial class EditAdherent : System.Web.UI.Page {
        private string adh_previd;
        public static readonly string source = "AdhEdition.aspx";

        protected void Page_Load(object sender, EventArgs e) {
                if (this.Request.Params.Count > 0) {
                    try {
                        adh_previd = Request.QueryString.Get("adh");

                        imgCancel.NavigateUrl = "/LAFDCWeb/AdhConsultation.aspx?adh=" + adh_previd;
                        // GenerateClientScript(adh_previd);
                        if (!IsPostBack){
                            LoadData(adh_previd);
                        }                            
                    }
                    catch{}
            }
        }

        private void LoadData(string adhid){
            FDCLogger.LogEvent("Le formulaire est en train de retrouver les informations existante", source, 4);
            ConnectionManager cn = new ConnectionManager();
            SqlConnection conn = cn.GetSqlConnection();

            #region // LOAD ASSO into listASSO
            string tsqlAsso = "select ad_id from Asso order by ad_id";
            SqlDataSource sourceAsso = new SqlDataSource(cn.GetConnectionString(), tsqlAsso);
            listASSO.DataSource = sourceAsso;
            listASSO.DataValueField = "ad_id";
            listASSO.DataBind();
            #endregion

            #region // LOAD Section into listSECTION
            string tsqlSection = "select [section id], [section_name] from Section order by [section id]";
            SqlDataSource sourceSection = new SqlDataSource(cn.GetConnectionString(), tsqlSection);
            FDCLogger.LogEvent("Preparing data bind on listSection", source, 4);
            listSECTION.DataSource = sourceSection;
            listSECTION.DataTextField = "section id";
            listSECTION.DataValueField = "section_name";
			
            try{
                listSECTION.DataBind();
            }
            catch (Exception ex) { FDCLogger.LogEvent(ex.Message, source, 1); }
            
            SqlCommand tsql = conn.CreateCommand();
            tsql.CommandType = CommandType.StoredProcedure;
            #endregion

            #region // ETAT CIVILE
            FDCLogger.LogEvent("ETAT CIVILE...", source, 4);
            tsql.CommandText = "spGetETAT_CIVILE_byPrevID";
            SqlParameter param = tsql.Parameters.Add("@PREV_ID", SqlDbType.NVarChar);
            param.Value = adhid;
            
            conn.Open();
            using (SqlDataReader reader = tsql.ExecuteReader()){
                int i = 0;
                while (reader.Read()){
                    if (i > 0) { 
						break;
					}
                    txtPREV_ID.Text = reader.GetValue(0).ToString();
                    txtNOM.Text = reader.GetValue(1).ToString();
                    txtPRENOM.Text = reader.GetValue(2).ToString();
                    
                    string Intitule = reader.GetValue(3).ToString();
                    if (Intitule == "???"){
                        listIntitule.SelectedValue = "";
                    }
                    else { listIntitule.SelectedValue = Intitule;}

                    string SitFamille = reader.GetValue(4).ToString();
                    if (SitFamille == "???") {
                        listSituationFamille.SelectedValue = "";
                    }
                    else { listSituationFamille.SelectedValue = SitFamille; }
                    txtANNIV.Text = reader.GetValue(5).ToString();
                    i++;
                }
            }
            conn.Close();
            #endregion
            #region //ADRESSE
            FDCLogger.LogEvent("ADRESSE...", source, 4);
            tsql.CommandText = "spGetADRESSE_byPrevID";
            conn.Open();

            using (SqlDataReader reader = tsql.ExecuteReader()) {
                while (reader.Read()) {
                    txtAdr1.Text = reader.GetString(0);
                    txtAdr2.Text = reader.GetString(1);
                    txtCodePostal.Text = reader.GetString(2);
                    txtVille.Text = reader.GetString(3);
                }
            }
            conn.Close(); 
            #endregion
            #region //STATUS
            try {
                FDCLogger.LogEvent("STATUS...", source, 4);
                tsql.CommandText = "spGetSTATUS_byPrevID";
                conn.Open();
                using (SqlDataReader reader = tsql.ExecuteReader()) {
                    while (reader.Read()) {
                        if ( !reader.IsDBNull(0)) {
                            FDCLogger.LogEvent("Loading AD to list, value=" + reader.GetString(0), source, 4);
                            if (listASSO.Items.Contains(new ListItem(reader.GetString(0)))) {
                                FDCLogger.LogEvent("The list contains the correct AD value!", source, 4);
                                listASSO.SelectedValue = reader.GetString(0);
                            }
                        }
                        if (!reader.IsDBNull(1)) {
                            if (reader.GetString(1) != "0"){
                                listSECTION.SelectedValue = reader.GetString(1);
                            }
                            else { listSECTION.SelectedValue = ""; }
                        }
                        if (!reader.IsDBNull(2)) {
                            if (reader.GetString(2) == "OUI"){
                                chkRETENU.Checked = true;
                            }
                        }
                        if (!reader.IsDBNull(4)){
                            txtIRET.Text = reader.GetString(4);
                        }
                        if (!reader.IsDBNull(5)){
                            txtOTIG.Text = reader.GetString(5);
                        }
                        if (!reader.IsDBNull(6)){
                            txtADHESION.Text = reader.GetValue(6).ToString();
                        }
                        if (!reader.IsDBNull(7)){
                            txtAFFECTATION.Text = reader.GetString(7);
                        }
                        break;
                    }
                }
                conn.Close();
                FDCLogger.LogEvent("STATUS...OKAY!", source, 4);
            }
            catch (Exception ex) {
                FDCLogger.LogEvent(ex.InnerException.ToString(), source, 1);
            }
            #endregion
            #region // CONTACT
            try {
                FDCLogger.LogEvent("CONTACTS...", source, 4);
                tsql.CommandText = "spGetCONTACT_byPrevID";
                conn.Open();
                using (SqlDataReader reader = tsql.ExecuteReader()) {
                    int i = 0;

                    string curRef = string.Empty;
                    string curValue = string.Empty;
                    string curType = string.Empty;
                    string curDesc = string.Empty;

                    ListItem current;

                    while (reader.Read()) {
                        curRef = reader.GetValue(0).ToString();
                        curValue = reader.GetValue(1).ToString();
                        curType = reader.GetValue(2).ToString();

                        current = new ListItem(curType);

                        curDesc = reader.GetValue(3).ToString();

                        i++;
                        switch (i) {
                            case 1: {
                                    lblRef1.Text = curRef;
                                    txtContact1.Text = curValue;
                                    listContact1.SelectedValue = curType;
                                    txtContact1Desc.Text = curDesc;
                                    break;
                                }
                            case 2: {
                                    lblRef2.Text = curRef;
                                    txtContact2.Text = curValue;
                                    listContact2.SelectedValue = curType;
                                    txtContact2Desc.Text = curDesc;

                                    break;
                                }
                            case 3: {
                                    lblRef3.Text = curRef;
                                    txtContact3.Text = curValue;
                                    listContact3.SelectedValue = curType;
                                    txtContact3Desc.Text = curDesc;

                                    break;
                                }
                            case 4: {
                                    lblRef4.Text = curRef;
                                    txtContact4.Text = curValue;
                                    listContact4.SelectedValue = curType;
                                    txtContact4Desc.Text = curDesc;

                                    break;
                                }
                            case 5: {
                                    lblRef5.Text = curRef;
                                    txtContact5.Text = curValue;
                                    listContact5.SelectedValue = curType;
                                    txtContact5Desc.Text = curDesc;

                                    break;
                                }
                        }
                        //Ensure the local variable values are set back to null
                        curRef = string.Empty;
                        curValue = string.Empty;
                        curType = string.Empty;
                        curDesc = string.Empty;
                    }
                }
                conn.Close();
            }
            catch (Exception ex) {
                FDCLogger.LogEvent(ex.InnerException.ToString(), source, 1);
            }
            #endregion
        }

        protected void Submit_Click(object sender, EventArgs e) {
            FDCLogger.LogEvent("Enregistrement du formulaire initialisee", source, 4);
            // Gather modified information from page, load and display back
            string temp = string.Empty;

            if (this.IsPostBack) {
                lblDEBUG.Text = string.Empty;
                foreach (string changedObject in FormChangeTracker.mChangedObjects) {
                    FDCLogger.LogEvent("Le formulaire a ete change pour la section " + changedObject, source, 4);
                }

                ConnectionManager cn = new ConnectionManager();
                SqlConnection conn = cn.GetSqlConnection();
                SqlCommand tsql = conn.CreateCommand();

                string PREV_ID = adh_previd;
                #region// UPDATE ADHERENT [logging added]
                if (FormChangeTracker.mChangedObjects.Contains("ADHERENT")) {
                    string Asso = listASSO.Text;
                    string Section = listSECTION.SelectedValue;
                    string Retenu = string.Empty;

                    if (chkRETENU.Checked) {
                        Retenu = "OUI";
                    }
                    else { Retenu = "NON"; }

                    string Adhesion = txtADHESION.Text;

                    tsql.CommandType = CommandType.Text;
                    tsql.CommandText = @"update adherent
    set ad		    	= '" + Asso + @"',
	    section 		= '" + Section + @"',
	    retenu  		= '" + Retenu + @"',
	    date_adhesion	= '" + Adhesion + @"'
    where prev_id	    = '" + PREV_ID + "'";

                    FDCLogger.LogEvent("Preparing to update adherent with: " + tsql.CommandText, source, 4);

                    conn.Open();
                    int result = tsql.ExecuteNonQuery();
                    conn.Close();
                    FormChangeTracker.mChangedObjects.Remove("ADHERENT");
                }

                #endregion
                #region // UPDATE ETAT CIVILE [logging added]
                if (FormChangeTracker.mChangedObjects.Contains("ETAT_CIVILE")) {
                    string Nom = txtNOM.Text;
                    string Prenom = txtPRENOM.Text;
                    string PrevID = txtPREV_ID.Text;
                    string Intitule = listIntitule.SelectedValue;
                    string SitFamille = listSituationFamille.SelectedValue;
                    string Anniv = txtANNIV.Text;

                    tsql.CommandType = CommandType.Text;
                    tsql.CommandText = @"update personne
    set nom					= '" + Nom + @"',
	    prenom				= '" + Prenom + @"',
	    [civ-sexe]			= '" + Intitule + @"',
	    sfam= '" + SitFamille + @"',
        anniv= '" + Anniv + @"'
    where prev_id = '" + PREV_ID + "' and sfam !='enfant' and sfam!='conjoint(e)'";

                    FDCLogger.LogEvent("Preparing to update personne with: " + tsql.CommandText, source, 4);

                    conn.Open();
                        int result = tsql.ExecuteNonQuery();
                    conn.Close();

                    FormChangeTracker.mChangedObjects.Remove("ETAT_CIVILE");
                }
                #endregion

                #region// UPDATE ADRESSE [logging added]
                if (FormChangeTracker.mChangedObjects.Contains("ADRESSE")) {
                    string Addr1 = txtAdr1.Text;
                    string Addr2 = txtAdr2.Text;
                    string CodePostal = txtCodePostal.Text;
                    string Ville = txtVille.Text;

                    tsql.CommandType = CommandType.Text;
                    tsql.CommandText = @"update adresse
    set adresse_1	= '" + Addr1 + @"',
	    adresse_2	= '" + Addr2 + @"',
	    codepostal	= '" + CodePostal + @"',
	    ville		= '" + Ville + @"'
    where prev_id	= '" + PREV_ID + "'";

                    FDCLogger.LogEvent("Preparing to update adresse with: " + tsql.CommandText, source, 4);
                    
                    conn.Open();
                    int result = tsql.ExecuteNonQuery();
                    conn.Close();
                    FormChangeTracker.mChangedObjects.Remove("ADRESSE");
                }
                #endregion
                #region//UPDATE DIVERS [logging added]
                if (FormChangeTracker.mChangedObjects.Contains("DIVERS")) {
                    string Affectation = txtAFFECTATION.Text;
                    string IRET = txtIRET.Text;
                    string OTIG = txtOTIG.Text;

                    tsql.CommandType = CommandType.Text;
                    tsql.CommandText = @"update divers
    set Affectation	= '" + Affectation + @"',
	    indice_retraite = '" + IRET + @"',
	    otig		= '" + OTIG + @"'
    where prev_id	= '" + PREV_ID + "'";

                    FDCLogger.LogEvent("Preparing to update 'divers' with: " + tsql.CommandText, source, 4);

                    conn.Open();
                    int result = tsql.ExecuteNonQuery();
                    conn.Close();
                    FormChangeTracker.mChangedObjects.Remove("DIVERS");
                }
                #endregion
                #region// UPDATE CONTACT [logging added]
                if (FormChangeTracker.mChangedObjects.Contains("CONTACT")) {
                    int ctrlId = 0;
                    string contactId = string.Empty;
                    string contactType = string.Empty;
                    string contactValue = string.Empty;
                    string contactDesc = string.Empty;
                    
                    bool isNewcontact = false;

                    FDCLogger.LogEvent("Found changes in contact!", source, 4);
                    foreach (string contactCode in FormChangeTracker.mChangedContact) {
                        #region // CHECK NEW vs EXISTING CONTACT
                        if (contactCode.StartsWith("New_")) {
                            ctrlId = Convert.ToInt32(contactCode.TrimStart("New_".ToCharArray()));
                            FDCLogger.LogEvent("Found a new contact in control at position " + ctrlId.ToString(), source, 4);
                            isNewcontact = true;
                        }
                        else { 
                            // This is an existing contact
                            // so we get it's position (control wise)
                            temp = contactCode.Substring(contactCode.Length - 1);
                            ctrlId = Convert.ToInt32(temp);
                            FDCLogger.LogEvent("Found an existing contact in control at position " + ctrlId.ToString(), source, 4);
                            
                            // as well as the contact id;
                            contactId = contactCode.Remove(contactCode.Length - 2);
                            FDCLogger.LogEvent("Contact ID is " + contactId.ToString(), source, 4);
                            isNewcontact = false;
                        }
                        #endregion
                        #region // Gather data from form
                        switch (ctrlId) {
                            case 1: {
                                    contactType = listContact1.Text;
                                    contactValue = txtContact1.Text;
                                    contactDesc = txtContact1Desc.Text;
                                    break;
                                }
                            case 2: {
                                    contactType = listContact2.Text;
                                    contactValue = txtContact2.Text;
                                    contactDesc = txtContact2Desc.Text;
                                    break;
                                }
                            case 3: {
                                    contactType = listContact3.Text;
                                    contactValue = txtContact3.Text;
                                    contactDesc = txtContact3Desc.Text;
                                    break;
                                }
                            case 4: {
                                    contactType = listContact4.Text;
                                    contactValue = txtContact4.Text;
                                    contactDesc = txtContact4Desc.Text;
                                    break;
                                }
                            case 5: {
                                    contactType = listContact5.Text;
                                    contactValue = txtContact5.Text;
                                    contactDesc = txtContact5Desc.Text;
                                    break;
                                }
                        }
                        #endregion
                        #region // New contact - insert
                        if (isNewcontact) {
                            // Insert into DB

                            tsql.CommandType = CommandType.Text;
                            tsql.CommandText = @"insert into contact (prev_id, type, valeur, description) values('" + PREV_ID + "','" + contactType + "','" + contactValue + "','" + contactDesc + "')";

                            FDCLogger.LogEvent("Preparing to insert contact with: " + tsql.CommandText, source, 3);
                            conn.Open();
                            tsql.ExecuteNonQuery();
                            conn.Close();
                        }
                        #endregion
                        #region // Existing contact - update
                        else{
                            // Update DB
                            tsql.CommandType = CommandType.Text;
                            tsql.CommandText = @"update contact set type='" + contactType + "', valeur='" + contactValue + "', description='"+ contactDesc +"' where id = '" + contactId + "'";
                            FDCLogger.LogEvent("Preparing to update contact with: " + tsql.CommandText, source, 3);

                            conn.Open();
                            tsql.ExecuteNonQuery();
                            conn.Close();
                        }
                        #endregion

                        ctrlId = 100;
                        isNewcontact = false;
                        contactId = string.Empty;
                        contactType = string.Empty;
                        contactValue = string.Empty;
                        contactDesc = string.Empty;
                    }
                }
                FormChangeTracker.mChangedContact.Clear();
                FormChangeTracker.mChangedObjects.Remove("CONTACT");
                #endregion

                Response.Redirect("AdhConsultation.aspx?adh=" + adh_previd);
            }
        }
        #region // Change Tracking events
        #region // ETAT_CIVILE
        protected void txtNOM_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ETAT_CIVILE");
        }
        protected void txtPRENOM_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ETAT_CIVILE");
        }
        protected void txtANNIV_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ETAT_CIVILE");
        }
        protected void listIntitule_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ETAT_CIVILE");
        }
        protected void listSituationFamille_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ETAT_CIVILE");
        }
        #endregion
        #region // ADRESSE
        protected void txtAdr1_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADRESSE");
        }
        protected void txtAdr2_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADRESSE");
        }
        protected void txtCodePostal_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADRESSE");
        }

        protected void txtVille_TextChanged(object sender, EventArgs e){
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADRESSE");
        }
        #endregion
        #region // ADHERENT
        protected void txtADHESION_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADHERENT");
        }
        protected void chkRETENU_CheckedChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADHERENT");
        }
        protected void listASSO_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADHERENT");
        }
        protected void listSECTION_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("ADHERENT");
        }
        #endregion
        #region // DIVERS
        protected void txtOTIG_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("DIVERS");
        }
        protected void txtIRET_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("DIVERS");
        }
        protected void txtAFFECTATION_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("DIVERS");
        }
        #endregion
        #region // CONTACT
        #region // CONTACT 1 CHANGED
        protected void listContact1_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef1.Text == "") {
                // Contact reference does not exist
                lblRef1.Text = "New";
            }
            tracker.RegisterContactChange(lblRef1.Text + "_1");
        }
        protected void txtContact1_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef1.Text == "") {
                // Contact reference does not exist
                lblRef1.Text = "New";
            }
            tracker.RegisterContactChange(lblRef1.Text + "_1");
        }
        protected void txtContact1Desc_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef1.Text == "") {
                // Contact reference does not exist
                lblRef1.Text = "New";
            }
            tracker.RegisterContactChange(lblRef1.Text + "_1");
        }
        #endregion
        #region // CONTACT 2 CHANGED
        protected void listContact2_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef2.Text == "") {
                // Contact reference does not exist
                lblRef2.Text = "New";
            }
            tracker.RegisterContactChange(lblRef2.Text + "_2");
        }
        protected void txtContact2_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef2.Text == "") {
                // Contact reference does not exist
                lblRef2.Text = "New";
            }
            tracker.RegisterContactChange(lblRef2.Text + "_2");
        }
        protected void txtContact2Desc_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef2.Text == "") {
                // Contact reference does not exist
                lblRef2.Text = "New";
            }
            tracker.RegisterContactChange(lblRef2.Text + "_2");
        }
        #endregion
        #region // CONTACT 3 CHANGED
        protected void listContact3_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef3.Text == "") {
                // Contact reference does not exist
                lblRef3.Text = "New";
            }
            tracker.RegisterContactChange(lblRef3.Text + "_3");
        }
        protected void txtContact3_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef3.Text == "") {
                // Contact reference does not exist
                lblRef3.Text = "New";
            }
            tracker.RegisterContactChange(lblRef3.Text + "_3");
        }

        protected void txtContact3Desc_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef3.Text == "") {
                // Contact reference does not exist
                lblRef3.Text = "New";
            }
            tracker.RegisterContactChange(lblRef3.Text + "_3");
        }
        #endregion
        #region // CONTACT 4 CHANGED
        protected void listContact4_SelectedIndexChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef4.Text == "") {
                // Contact reference does not exist
                lblRef4.Text = "New";
            }
            tracker.RegisterContactChange(lblRef4.Text + "_4");
        }
        protected void txtContact4_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef4.Text == "") {
                // Contact reference does not exist
                lblRef4.Text = "New";
            }
            tracker.RegisterContactChange(lblRef4.Text + "_4");
        }
        protected void txtContact4Desc_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            if (lblRef4.Text == "") {
                // Contact reference does not exist
                lblRef4.Text = "New";
            }
            tracker.RegisterContactChange(lblRef4.Text + "_4");
        }
        #endregion
        #region // CONTACT 5 CHANGED
        protected void listContact5_SelectedIndexChanged(object sender, EventArgs e){
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            // lblDEBUG.Text += "<br>Adding a contact change now!";
            if (lblRef5.Text == "") {
                // Contact reference does not exist
                lblRef5.Text = "New";
                // lblDEBUG.Text += "<BR>This is a new entry!";
            }
            tracker.RegisterContactChange(lblRef5.Text + "_5");
        }
        protected void txtContact5_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            // lblDEBUG.Text += "<br>Adding a contact change now!";
            if (lblRef5.Text == "") {
                // Contact reference does not exist
                lblRef5.Text = "New";
                // lblDEBUG.Text += "<BR>This is a new entry!";
            }
            tracker.RegisterContactChange(lblRef5.Text + "_5");
        }
        protected void txtContact5Desc_TextChanged(object sender, EventArgs e) {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("CONTACT");
            // lblDEBUG.Text += "<br>Adding a contact change now!";
            if (lblRef5.Text == "") {
                // Contact reference does not exist
                lblRef5.Text = "New";
                // lblDEBUG.Text += "<BR>This is a new entry!";
            }
            tracker.RegisterContactChange(lblRef5.Text + "_5");
        }
        #endregion
        #endregion
        #endregion
    }
}
